<?php
//=======================================
//###################################
// Kayako Web Solutions
//
// Source Copyright 2001-2004 Kayako Web Solutions
// Unauthorized reproduction is not allowed
// License Number: $%LICENSE%$
// $Author: mslaria $ ($Date: 2006/12/22 10:13:57 $)
// $RCSfile: functions_taskrender.php,v $ : $Revision: 1.12 $ 
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
//###################################
//=======================================


if (!defined("INSWIFT")) {
	trigger_error("Unable to process $PHP_SELF", E_USER_ERROR);
}

/**
* Return the Options with selected tabs
*/
function getTaskGridOptions()
{
	global $_SWIFT;

	$options = array();
	$options["tabs"][0]["title"] = $_SWIFT["language"]["simplelist"];
	$options["tabs"][0]["url"] = "index.php?_m=teamwork&_a=tasks&viewtype=".TASKVIEW_SIMPLE;
	$options["tabs"][0]["selected"] = iif($_REQUEST["viewtype"]==TASKVIEW_SIMPLE, true, false);
	$options["tabs"][1]["title"] = $_SWIFT["language"]["detailedlist"];
	$options["tabs"][1]["url"] = "index.php?_m=teamwork&_a=tasks&viewtype=".TASKVIEW_DETAILED;
	$options["tabs"][1]["selected"] = iif($_REQUEST["viewtype"]==TASKVIEW_DETAILED||empty($_REQUEST["viewtype"]), true, false);
	$options["tabs"][2]["title"] = $_SWIFT["language"]["nextsevendays"];
	$options["tabs"][2]["url"] = "index.php?_m=teamwork&_a=tasks&viewtype=".TASKVIEW_NEXTSEVENDAYS;
	$options["tabs"][2]["selected"] = iif($_REQUEST["viewtype"]==TASKVIEW_NEXTSEVENDAYS, true, false);
	$options["tabs"][3]["title"] = $_SWIFT["language"]["overduetasks"];
	$options["tabs"][3]["url"] = "index.php?_m=teamwork&_a=tasks&viewtype=".TASKVIEW_OVERDUE;
	$options["tabs"][3]["selected"] = iif($_REQUEST["viewtype"]==TASKVIEW_OVERDUE, true, false);
	$options["tabs"][4]["title"] = $_SWIFT["language"]["byassignment"];
	$options["tabs"][4]["url"] = "index.php?_m=teamwork&_a=tasks&viewtype=".TASKVIEW_BYASSIGNMENT;
	$options["tabs"][4]["selected"] = iif($_REQUEST["viewtype"]==TASKVIEW_BYASSIGNMENT, true, false);
	$options["tabs"][5]["title"] = $_SWIFT["language"]["completedtasks"];
	$options["tabs"][5]["url"] = "index.php?_m=teamwork&_a=tasks&viewtype=".TASKVIEW_COMPLETED;
	$options["tabs"][5]["selected"] = iif($_REQUEST["viewtype"]==TASKVIEW_COMPLETED, true, false);

	return $options;
}

/**
* Return the Sort Field Data
*/
function getTaskGridSort($_viewtype)
{
	global $_SWIFT;

	if ($_viewtype == TASKVIEW_SIMPLE || $_viewtype == TASKVIEW_DETAILED)
	{
		return array("duedate", "asc");
	} else if ($_viewtype == TASKVIEW_NEXTSEVENDAYS) {
		return array("duedate", "desc");
	} else if ($_viewtype == TASKVIEW_OVERDUE) {
		return array("duedate", "asc");
	} else if ($_viewtype == TASKVIEW_BYASSIGNMENT) {
		return array("ownerstaffid", "asc");
	}

	return array("subject", "asc");
}

/**
* Return the Task Grid Fields based on View Type
*/
function getTaskGridFields($_viewtype)
{
	global $_SWIFT;

	$fields = array();

	switch ($_viewtype)
	{
		case TASKVIEW_SIMPLE:
			$fields[0]["name"] = "taskimg";
			$fields[0]["title"] = "&nbsp;";
			$fields[0]["width"] = "16";
			$fields[0]["type"] = "custom";

			$fields[1]["name"] = "subject";
			$fields[1]["title"] = $_SWIFT["language"]["subject"];
			$fields[1]["width"] = "";

			$fields[2]["name"] = "duedate";
			$fields[2]["title"] = $_SWIFT["language"]["due"];
			$fields[2]["width"] = "150";
			$fields[2]["align"] = "center";
			break;
	
		case TASKVIEW_DETAILED:
			$fields[0]["name"] = "taskimg";
			$fields[0]["title"] = "&nbsp;";
			$fields[0]["width"] = "16";
			$fields[0]["type"] = "custom";

			$fields[1]["name"] = "subject";
			$fields[1]["title"] = $_SWIFT["language"]["subject"];
			$fields[1]["width"] = "";

			$fields[2]["name"] = "calendarstatusid";
			$fields[2]["title"] = $_SWIFT["language"]["status"];
			$fields[2]["width"] = "180";
			$fields[2]["align"] = "center";

			$fields[3]["name"] = "duedate";
			$fields[3]["title"] = $_SWIFT["language"]["due"];
			$fields[3]["width"] = "150";
			$fields[3]["align"] = "center";

			$fields[4]["name"] = "completepercent";
			$fields[4]["title"] = $_SWIFT["language"]["percomplete"];
			$fields[4]["width"] = "150";
			$fields[4]["align"] = "center";
			break;
	
		case TASKVIEW_COMPLETED:
			$fields[0]["name"] = "taskimg";
			$fields[0]["title"] = "&nbsp;";
			$fields[0]["width"] = "16";
			$fields[0]["type"] = "custom";

			$fields[1]["name"] = "subject";
			$fields[1]["title"] = $_SWIFT["language"]["subject"];
			$fields[1]["width"] = "";

			$fields[2]["name"] = "calendarstatusid";
			$fields[2]["title"] = $_SWIFT["language"]["status"];
			$fields[2]["width"] = "180";
			$fields[2]["align"] = "center";

			$fields[3]["name"] = "ownerstaffid";
			$fields[3]["title"] = $_SWIFT["language"]["owner"];
			$fields[3]["width"] = "200";
			$fields[3]["align"] = "center";

			$fields[4]["name"] = "completepercent";
			$fields[4]["title"] = $_SWIFT["language"]["percomplete"];
			$fields[4]["width"] = "150";
			$fields[4]["align"] = "center";
			break;
	
		case TASKVIEW_NEXTSEVENDAYS:
			$fields[0]["name"] = "taskimg";
			$fields[0]["title"] = "&nbsp;";
			$fields[0]["width"] = "16";
			$fields[0]["type"] = "custom";

			$fields[1]["name"] = "subject";
			$fields[1]["title"] = $_SWIFT["language"]["subject"];
			$fields[1]["width"] = "";

			$fields[2]["name"] = "calendarstatusid";
			$fields[2]["title"] = $_SWIFT["language"]["status"];
			$fields[2]["width"] = "180";
			$fields[2]["align"] = "center";

			$fields[3]["name"] = "duedate";
			$fields[3]["title"] = $_SWIFT["language"]["due"];
			$fields[3]["width"] = "150";
			$fields[3]["align"] = "center";

			$fields[4]["name"] = "completepercent";
			$fields[4]["title"] = $_SWIFT["language"]["percomplete"];
			$fields[4]["width"] = "150";
			$fields[4]["align"] = "center";
			break;
	
		case TASKVIEW_OVERDUE:
			$fields[0]["name"] = "taskimg";
			$fields[0]["title"] = "&nbsp;";
			$fields[0]["width"] = "16";
			$fields[0]["type"] = "custom";

			$fields[1]["name"] = "subject";
			$fields[1]["title"] = $_SWIFT["language"]["subject"];
			$fields[1]["width"] = "";

			$fields[2]["name"] = "calendarstatusid";
			$fields[2]["title"] = $_SWIFT["language"]["status"];
			$fields[2]["width"] = "180";
			$fields[2]["align"] = "center";

			$fields[3]["name"] = "duedate";
			$fields[3]["title"] = $_SWIFT["language"]["due"];
			$fields[3]["width"] = "150";
			$fields[3]["align"] = "center";

			$fields[4]["name"] = "completepercent";
			$fields[4]["title"] = $_SWIFT["language"]["percomplete"];
			$fields[4]["width"] = "150";
			$fields[4]["align"] = "center";
			break;
	
		case TASKVIEW_BYASSIGNMENT:
			$fields[0]["name"] = "taskimg";
			$fields[0]["title"] = "&nbsp;";
			$fields[0]["width"] = "16";
			$fields[0]["type"] = "custom";

			$fields[1]["name"] = "subject";
			$fields[1]["title"] = $_SWIFT["language"]["subject"];
			$fields[1]["width"] = "";

			$fields[2]["name"] = "ownerstaffid";
			$fields[2]["title"] = $_SWIFT["language"]["owner"];
			$fields[2]["width"] = "200";
			$fields[2]["align"] = "center";

			$fields[3]["name"] = "duedate";
			$fields[3]["title"] = $_SWIFT["language"]["due"];
			$fields[3]["width"] = "150";
			$fields[3]["align"] = "center";

			$fields[4]["name"] = "calendarstatusid";
			$fields[4]["title"] = $_SWIFT["language"]["status"];
			$fields[4]["width"] = "180";
			$fields[4]["align"] = "center";

			$fields[5]["name"] = "completepercent";
			$fields[5]["title"] = $_SWIFT["language"]["percomplete"];
			$fields[5]["width"] = "150";
			$fields[5]["align"] = "center";
			break;
	}

	return $fields;
}

/**
* Callback for parsing Task data
*/
function _taskFields($arg)
{
	global $_SWIFT;
	$record = &$arg[0];
	$fields = &$arg[1];

	if ($record["tasktype"] == SWIFTPUBLIC)
	{
		$record["taskimg"] = '<img src="'. $_SWIFT["themepath"] .'icon_task.gif" border="0" align="absmiddle" />';
	} else if ($record["tasktype"] == SWIFTPRIVATE) {
		$record["taskimg"] = '<img src="'. $_SWIFT["themepath"] .'icon_taskprivate.gif" border="0" align="absmiddle" />';
	}

	$record["subject"] = '<a href="index.php?_m=teamwork&_a=edittask&calendartaskid='. intval($record["calendartaskid"]) .'">'.iif($record["iscomplete"]==1,"<s>").htmlspecialchars($record["subject"]).iif($record["iscomplete"]==1,"</s>").'</a>';

	$record["calendarcategoryid"] = $_SWIFT["calendarcategorycache"][$record["calendarcategoryid"]];
	$record["calendarstatusid"] = $_SWIFT["calendarstatuscache"][$record["calendarstatusid"]]["title"];

	$record["completepercent"] = intval($record["completepercent"])."%";

	$record["overdue"] = false;
	if ($record["duedate"] != 0)
	{
		if (date("d", $record["duedate"]) == date("d", DATENOW) && date("m", $record["duedate"]) == date("m", DATENOW) && date("Y", $record["duedate"]) == date("Y", DATENOW))
		{
			// Due today
			$record["duedate"] = '<span class=\'tickettextblue\'>'.$_SWIFT["language"]["twtoday"].'</span>';
		} else if (DATENOW >= $record["duedate"]) {
			// Overdue
			$record["duedate"] = '<span class=\'tickettextred\'>'.$_SWIFT["language"]["overdue"].'</span>';
			$record["overdue"] = true;
		} else {
			$record["duedate"] = strColorDate(($record["duedate"]-DATENOW), true);
		}
	} else {
		$record["duedate"] = "";
	}

	$record["ownerstaffid"] = htmlspecialchars($_SWIFT["staffcache"][$record["ownerstaffid"]]["fullname"]);

	return $record;
}

/**
* Mass Action: Delete Tasks
*/
function _maDeleteTasks()
{
	global $dbCore, $_SWIFT;

	if (_is_array($_POST["itemid"]))
	{
		deleteCalendarTasks($_POST["itemid"]);
		$_SWIFT["infomessage"] = $_SWIFT["language"]["taskdelconfirmmul"];
	}
}

/**
* Mass Action: Mark Tasks as Overdue
*/
function _maMarkAsOverdue()
{
	global $dbCore, $_SWIFT;

	if (_is_array($_POST["itemid"]))
	{
		markTasksAsOverdue($_POST["itemid"]);
		$_SWIFT["infomessage"] = $_SWIFT["language"]["taskovdconfirm"];
	}
}

/**
* Mass Action: Mark Tasks as Incomplete
*/
function _maMarkAsInComplete()
{
	global $dbCore, $_SWIFT;

	if (_is_array($_POST["itemid"]))
	{
		markTasksAsInComplete($_POST["itemid"]);
		$_SWIFT["infomessage"] = $_SWIFT["language"]["taskincompconfirm"];
	}
}

/**
* Mass Action: Mark Tasks as Complete
*/
function _maMarkAsComplete()
{
	global $dbCore, $_SWIFT;

	if (_is_array($_POST["itemid"]))
	{
		markTasksAsComplete($_POST["itemid"]);
		$_SWIFT["infomessage"] = $_SWIFT["language"]["taskcompconfirm"];
	}
}

/**
* Render the Task Form
*/
function renderTaskForm($type)
{
	global $dbCore, $_SWIFT;

	printFormStart("tfform", "index.php", "POST");
	echo '<table cellspacing="0" cellpadding="0" border="0" width="100%" id="caltableopt"><tr style="height: 1em"><td align="left"><div id="calopt"><ul id="tab">
	
	<li><a class="currenttab" href="#" onClick="this.blur(); switchGridTab(\'tfgeneral\', \'taskform\');" id="tfgeneral" title="'. $_SWIFT["language"]["general"] .'">'. $_SWIFT["language"]["general"] .'</a></li>
	<li><a href="#" onClick="this.blur(); switchGridTab(\'tfmisc\', \'taskform\');" id="tfmisc" title="'. $_SWIFT["language"]["misc"] .'">'. $_SWIFT["language"]["misc"] .'</a></li>
	<li><a href="#" onClick="this.blur(); switchGridTab(\'tfcustom\', \'taskform\');" id="tfcustom" title="'. $_SWIFT["language"]["custom"] .'">'. $_SWIFT["language"]["custom"] .'</a></li>
	</ul></div></td></tr>'.SWIFT_CRLF;

	echo '<tr style="height: 1em"><td align="left">'.SWIFT_CRLF;

	$buttontext = iif($type==INSERT, $_SWIFT["language"]["insert"], $_SWIFT["language"]["update"]);

	// ======= GENERAL TAB =======
	$tasktype = '<label for="tasktypeyes">'. '<input type="radio" name="tasktype" class="swiftradio" onClick="javascript:document.tfform.ownerstaffid.disabled=false;" id="tasktypeyes" value="public"'. iif($_POST["tasktype"]==SWIFTPUBLIC||empty($_POST["tasktype"]), " checked") .' />'.$_SWIFT["language"]["public"].'</label>'.SWIFT_CRLF;
	
	$tasktype .= '<label for="tasktypeno">'. '<input type="radio" name="tasktype" id="tasktypeno" onClick="javascript:document.tfform.ownerstaffid.disabled=true;" value="private"'. iif($_POST["tasktype"]==SWIFTPRIVATE, " checked") .' />'.$_SWIFT["language"]["private"].'</label>'.SWIFT_CRLF;

	$infolist[] = array($_SWIFT["language"]["tftype"], iif($type==DISPLAY, iif($_POST["tasktype"]==SWIFTPUBLIC, $_SWIFT["language"]["public"], $_SWIFT["language"]["private"]), $tasktype));

	$owner = '<select name="ownerstaffid" id="ownerstaffid" class="swiftselect"'. iif($_POST["tasktype"]==SWIFTPRIVATE, "disabled") .'>';
	foreach ($_SWIFT["staffcache"] as $key=>$val)
	{
		$owner .= '<option value="'. $val["staffid"] .'"'. iif($val["staffid"]==$_POST["ownerstaffid"]||($type==INSERT&&$_SWIFT["staff"]["staffid"]==$val["staffid"]), " selected") .'>'. htmlspecialchars($val["fullname"]) .'</option>';
	}
	$owner .= '</select>';
	$infolist[] = array($_SWIFT["language"]["tfowner"], iif($type==DISPLAY, $_SWIFT["staffcache"][$_POST["ownerstaffid"]]["fullname"], $owner));

	if ($type == INSERT)
	{
		$_startdate = iif(!empty($_GET["startdate"]), $_GET["startdate"], iif(!empty($_POST["startdate"]), calenderDateToDateline($_POST["startdate"])));
	} else if ($type == EDIT) {
		$_startdate = $_POST["startdate"];
	}

	$infolist[] = array($_SWIFT["language"]["tfstart"], iif($type==DISPLAY, iif(!empty($_POST["startdate"]), generateCalendarTimeline($_POST["startdate"])), '<input type="text" name="startdate" id="startdate" onclick="return showCalendar(\'startdate\', \''. iif($_SWIFT["settings"]["dt_caltype"]=="us", "%m/%d/%Y", "%d/%m/%Y") .'\');" size="12" readonly="1" value="'. iif(!empty($_startdate), iif($_SWIFT["settings"]["dt_caltype"]=="us", date("m/d/Y", $_startdate), date("d/m/Y",$_startdate))) .'" class="swifttext"/>&nbsp;<img src="'. $_SWIFT["themepath"] .'calendar.gif" onclick="return showCalendar(\'startdate\', \''. iif($_SWIFT["settings"]["dt_caltype"]=="us", "%m/%d/%Y", "%d/%m/%Y") .'\');" style="cursor: pointer;" align="absmiddle"/>'));

	if ($type == INSERT)
	{
		if (!empty($_POST["duedate"]))
		{
			$_duedate = calenderDateToDateline($_POST["duedate"]);
		}
	} else if ($type == EDIT) {
		if (!empty($_POST["duedate"]))
		{
			$_duedate = $_POST["duedate"];
		}
	}
	

	$infolist[] = array($_SWIFT["language"]["tfdue"], iif($type==DISPLAY, iif(!empty($_POST["duedate"]), generateCalendarTimeline($_POST["duedate"])), '<input type="text" name="duedate" id="duedate" onclick="return showCalendar(\'duedate\', \''. iif($_SWIFT["settings"]["dt_caltype"]=="us", "%m/%d/%Y", "%d/%m/%Y") .'\');" size="12" readonly="1" value="'. iif(!empty($_duedate),  iif($_SWIFT["settings"]["dt_caltype"]=="us", date("m/d/Y", $_duedate), date("d/m/Y", $_duedate))) .'" class="swifttext"/>&nbsp;<img src="'. $_SWIFT["themepath"] .'calendar.gif" onclick="return showCalendar(\'duedate\', \''. iif($_SWIFT["settings"]["dt_caltype"]=="us", "%m/%d/%Y", "%d/%m/%Y") .'\');" style="cursor: pointer;" align="absmiddle"/>'));

	$infolist[] = array($_SWIFT["language"]["tfpcomplete"], iif($type==DISPLAY, $_POST["completepercent"]."%", '<input type="text" class="swifttext" name="completepercent" value="'. $_POST["completepercent"] .'" size="5" />'));

	$label = '<select name="calendarlabelid" class="swiftselect">';
	$label .= '<option value="0" style="COLOR:'. "#666666" .';"'. iif($_POST["calendarlabelid"]==0, " selected") .'>'. htmlspecialchars($_SWIFT["language"]["tfnone"]) .'</option>';
	foreach ($_SWIFT["calendarlabelcache"] as $key=>$val)
	{
		if ($val["labeltype"] == LABEL_TASK)
		{
			$label .= '<option value="'. $val["calendarlabelid"] .'" style="COLOR:'. $val["labelcolorcode"] .';"'. iif($val["calendarlabelid"]==$_POST["calendarlabelid"], " selected") .'>'. htmlspecialchars($val["title"]) .'</option>';
		}
	}
	$label .= '</select>';
	$infolist[] = array($_SWIFT["language"]["tflabel"], iif($type==DISPLAY, '<font color="'. $_SWIFT["calendarlabelcache"][$_POST["calendarlabelid"]]["labelcolorcode"] .'">'.$_SWIFT["calendarlabelcache"][$_POST["calendarlabelid"]]["title"].'</font>', $label));

	$status = '<select name="calendarstatusid" class="swiftselect">';
	$status .= '<option value="0" style="COLOR:'. "#666666" .';"'. iif($_POST["calendarstatusid"]==0, " selected") .'>'. htmlspecialchars($_SWIFT["language"]["tfnone"]) .'</option>';
	foreach ($_SWIFT["calendarstatuscache"] as $key=>$val)
	{
		if ($val["statustype"] == STATUS_TASK)
		{
			$status .= '<option value="'. $val["calendarstatusid"] .'" style="COLOR:'. $val["statuscolorcode"] .';"'. iif($val["calendarstatusid"]==$_POST["calendarstatusid"], " selected") .'>'. htmlspecialchars($val["title"]) .'</option>';
		}
	}
	$status .= '</select>';
	$infolist[] = array($_SWIFT["language"]["tfstatus"], iif($type==DISPLAY, '<font color="'. $_SWIFT["calendarstatuscache"][$_POST["calendarstatusid"]]["statuscolorcode"] .'">'.$_SWIFT["calendarstatuscache"][$_POST["calendarstatusid"]]["title"].'</font>', $status));

	$priority = '<select name="calendarpriorityid" class="swiftselect">';
	$priority .= '<option value="0" style="COLOR:'. "#666666" .';"'. iif($_POST["calendarpriorityid"]==0, " selected") .'>'. htmlspecialchars($_SWIFT["language"]["tfnone"]) .'</option>';
	foreach ($_SWIFT["calendarprioritycache"] as $key=>$val)
	{
		$priority .= '<option value="'. $val["calendarpriorityid"] .'" style="COLOR:'. $val["prioritycolorcode"] .';"'. iif($val["calendarpriorityid"]==$_POST["calendarpriorityid"], " selected") .'>'. htmlspecialchars($val["title"]) .'</option>';
	}
	$priority .= '</select>';
	$infolist[] = array($_SWIFT["language"]["tfpriority"], iif($type==DISPLAY, '<font color="'. $_SWIFT["calendarprioritycache"][$_POST["calendarpriorityid"]]["prioritycolorcode"] .'">'.$_SWIFT["calendarprioritycache"][$_POST["calendarpriorityid"]]["title"].'</font>', $priority));

	echo '<div id="tab_tfgeneral" style="DISPLAY: block;" class="tabcontent">';
	echo '<table border="0" cellpadding="3" cellspacing="1" width="100%" class="tborder">';
	echo '<tr><td colspan="4" class="cleanrow"><table border="0" cellpadding="0" cellspacing="3" width="100%" class="smalltext"><tr><td width="1" nowrap><span class="smalltext">'.$_SWIFT["language"]["tfsubject"].'</span></td><td>'.iif($type==DISPLAY, htmlspecialchars($_POST["subject"]), '<input type="text" class="swifttext" name="subject" value="'. $_POST["subject"] .'" size="30" style="WIDTH:98%;" />') .'</td></tr></table></td></tr>';
	renderSplitFields($infolist, "row2", "cleanrow");
	if ($type == INSERT || $type == EDIT)
	{
		printSubmitRow($buttontext, "4");
	}
	echo '</table><BR />';
	echo '</div>';

	// ======= MISC TAB =======
	unset($infolist);
	echo '<div id="tab_tfmisc" style="DISPLAY: none;" class="tabcontent">';
	echo '<table border="0" cellpadding="3" cellspacing="1" width="100%" class="tborder">';
	renderSplitFields($infolist, "row2", "cleanrow");
	echo '<tr class="descrow">
<td class="descrow" align="left" valign="top" colspan="4">'. $_SWIFT["language"]["tfdescription"] .'</td>
</tr>';
	echo '<tr><td colspan="4" class="cleanrow">'.iif($type==DISPLAY, nl2br(htmlspecialchars($_POST["contents"])), '<textarea style="WIDTH: 98%;" class="swifttextarea" name="body" cols="50" rows="6">'. htmlspecialchars($_POST["contents"]) .'</textarea>') .'</td></tr>';
	if ($type == INSERT || $type == EDIT)
	{
		printSubmitRow($buttontext, "4");
	}
	echo '</table><BR />';
	
	echo '</div>';

	// ======= CUSTOM FIELD TAB =======
	echo '<div id="tab_tfcustom" style="DISPLAY: none;" class="tabcontent">';
	echo '<table border="0" cellpadding="3" cellspacing="1" width="100%" class="tborder">';

	ob_start();
	renderStaffCustomFields(CUSTOMFIELD_TASK, false, iif($type==EDIT||$type==DISPLAY, $_POST["calendartaskid"], 0));
	$contents = ob_get_contents();
	ob_end_clean();
	if (trim($contents) == "")
	{
		echo '<tr><td class="row2">'. $_SWIFT["language"]["nocferror"] .'</td></tr>';
	} else {
		echo $contents;
		if ($type == INSERT || $type == EDIT)
		{
			printSubmitRow($buttontext, "4");
		}
	}

	echo '</table><BR />';
	echo '</div>';

	echo '</td></tr></table>';
	printHiddenField("_m", "teamwork");
	printHiddenField("_a", iif($type==INSERT, "inserttask", "edittask"));
	printHiddenField("step", "1");
	printHiddenField("mode", "edit");
	if ($type == EDIT)
	{
		printHiddenField("calendartaskid", $_POST["calendartaskid"]);
	}
	printFormEnd();

}

?>